package tech.yangzhijie.basic.demo01;


import org.junit.Test;
import tech.yangzhijie.basic.demo01.model.Student;

import java.time.DayOfWeek;

public class Tests {

    @Test
    public void method01(){
        int a = 1;
        int b = 2;
        System.out.printf("a:%s\t",a);
        System.out.printf("b:%s\n",b);
        swap(a,b);
        System.out.printf("a:%s\t",a);
        System.out.printf("b:%s\n",b);
    }

    public void swap(int a,int b){
        //b = (a+b)-(a=b);
        int temp = a;
        a = b;
        b = temp;
        System.out.printf("a:%s\t",a);
        System.out.printf("b:%s\n",b);
    }

    @Test
    public void method02(){
        int[] arr = {1,2,3,4,5};
        System.out.println(arr[0]);
        change(arr);
        System.out.println(arr[0]);
    }

    public void change(int[] array){
        array[0] = -1;
    }

    /**
     * 说明java总是值传递，并不是引用传递,
     * 1.基本数据类型传递，复制值到方法形参中，形参值改变对方法外不起作用
     * 2.对象传递，是直接复制一个引用，这两个引用都指向同一个对象，set对象的值，两个对象都发生改变。
     * 3.对象传递，方法形参的引用
     */
    @Test
    public void mathod03(){
        Student s1 = new Student("阿珍");
        Student s2 = new Student("阿强");
        System.out.printf("s1:%s\t",s1.getName());
        System.out.printf("s2:%s\n",s2.getName());
        swap02(s1,s2);
        System.out.printf("s1:%s\t",s1.getName());
        System.out.printf("s2:%s\n",s2.getName());
    }

    public void swap02(Student s1,Student s2){
        Student temp = s1;
        s1 = s2;
        s2 = temp;
        s2.setName("阿衰");
        System.out.printf("s3:%s\t",s1.getName());
        System.out.printf("s4:%s\n",s2.getName());
    }

    @Test
    public void method04(){
        Student s1 = new Student("阿珍");
        System.out.println(s1.hashCode());
    }

    @Test
    public void method05(){
        System.out.println(DayOfWeek.SUNDAY.getValue());
    }


    @Test
    public void method06(){


    }


}
